<?php


namespace app\api\controller;


use app\api\model\GoodsModel;
use app\api\model\MeetingModel;
use app\api\model\OcrInfoModel;
use app\api\model\TengXunModel;
use app\api\model\UserModel;
use app\api\model\VoiceModel;
use app\api\model\YunXinModel;
use app\api\validate\MeetingValidate;
use think\Db;
use think\Exception;
use Workerman\Worker;

class Meeting extends ApiBase
{

    /**
     *
     * 专家列表
     */
    public function expertList(){

        $data = UserModel::expertList();
        $this->successful('查询成功',$data);
    }

    /**
     *
     * 向专家发送会议邀请
     */
    public function meetingAdd(MeetingValidate $request){

        $params = $this->request->post();
        $params['user_id'] = $this->id;
        if (!$request->scene('meetingAdd')->check($params)){

            $this->fail($request->getError());
        }
        $res = MeetingModel::meetingAdd($params);
        if ($res){

            $this->successful('发送成功',$res);
        }else{

            $this->fail('发送失败');
        }
    }

    /**
     *
     * 会议列表
     */
    public function meetingList(){

        $params = input();
        $type = isset($params['type']) ? $params['type'] : 0;
        $data = MeetingModel::meetingList($this->id,$type);
        $this->successful('查询成功',$data);
    }

    /**
     *
     * 结束会议
     */
    public function meetingDel(){

        $params = $this->request->post();
        if (!isset($params['meeting_id']) || empty($params['meeting_id'])){

            $this->fail('缺少meeting_id');
        }
        $res = TengXunModel::meetingDel($params['meeting_id']);
        if ($res){

            $this->successful('结束成功');
        }else{

            $this->fail('结束失败');
        }
    }

    /**
     *
     * 会议结束回到回调
     */
    public function meetingNotify(){

        $params = input();

        #录制会议回调事件
        if ($params['EventType'] == 311){

           // $url = 'http://jdvodlhltdtya.vod.126.net/jdvodlhltdtya/7005800-1348098866595815-1720148924328-0.mp4';
            p($params['EventInfo']['Payload']);
            p($params['EventInfo']['Payload']['TencentVod']);
            p($params['EventInfo']['Payload']['TencentVod']['VideoUrl']);
            MeetingModel::meetingEdit(['meeting_id'=>$params['EventInfo']['RoomId']],['meeting_url'=>$params['EventInfo']['Payload']['TencentVod']['VideoUrl'],'update_at'=>time()]);
        }
    }

    /**
     *
     * 会议详情
     */
    public function meetingInfo(){

        $params = $this->request->get();
        if (!isset($params['id']) || empty($params['id'])){

            $this->fail('缺少会议id');
        }

        $data = MeetingModel::meetingInfo($params['id'],$this->id);
        $this->successful('查询成功',$data);
    }


    /**
     *
     * 录音文件识别请求
     */
    public function recordDistinguish(){

        try{

            $params = $this->request->post();
            if (!isset($params['url']) || empty($params['url'])){

                $this->fail('缺少文件地址');
            }

            $res = VoiceModel::recordDistinguish($params['url']);
            if ($res){

                $this->successful('请求成功',$res);
            }else{

                $this->fail('请求失败');
            }
        }catch (Exception $exception){

            $this->fail($exception->getMessage());
        }

    }

    /**
     *
     * 语音识别结果
     */
    public function recordDistinguishResult(){

        try{

            $params = $this->request->post();
            if (!isset($params['taskId']) || empty($params['taskId'])){

                $this->fail('缺少taskId');
            }

            $res = VoiceModel::recordDistinguishResult($params['taskId']);
            if ($res){

                $this->successful('请求成功',$res);
            }else{

                $this->fail('请求失败');
            }
        }catch (Exception $exception){

            $this->fail($exception->getMessage());
        }

    }

    /**
     *
     * ocr病例信息添加
     */
    public function ocrInfoList(){

        $params = $this->request->post();
        if (!isset($params['meeting_id']) || empty($params['meeting_id'])){

            $this->fail('缺少meeting_id');
        }
        $data=  OcrInfoModel::ocrInfoList($params['meeting_id']);
        $this->successful('查询成功',$data);
    }
}